<template>
  <div class="seckill w">
    <!-- 头部 -->
    <div class="seckill-head">
      <div class="seckill-icon">
        <img src="../images/clock.png">
      </div>
      <div class="seckill-text">
        <span class="seckill-title">餐品列表</span></span>
        <span class="seckill-remarks">总有你想不到的低价</span>
      </div>
    </div>
    <!-- 内容 -->
    <div class="seckill-content" v-loading="goodsLoading" v-if="goodsList.length > 0">
      <div class="seckill-item" v-for="(item,index) in goodsList" :key="index" @click="goRouter(item)">
        <div class="seckill-item-img">
          <img style="width:100%;height:100%" :src="item.picture">
        </div>
        <div class="seckill-item-info">
          <p class="item-title">{{item.commodity}}</p>
          <p>
            <span class="seckill-price text-danger">
              {{item.price}}
            </span>
            <!-- <span class="seckill-old-price">300元</span> -->
          </p>
        </div>
      </div>
      <div style="clear: both;"></div>
    </div>
    <el-empty :image-size="200" v-else></el-empty>
  </div>
</template>

<script>
import EventBus from '@/utils/EventBus'
import { getGoodsList } from '@/api/goods'
export default {
  data() {
    return {
      goodsList: [],
      goodsLoading: false
    }
  },
  created() {
    this.getList()
    EventBus.$on('searchGoods', value => {
      this.goodsLoading = true
      getGoodsList(value).then(res => {
        this.goodsLoading = false
        this.goodsList = res.rows
      })
    })
  },
  mounted() {

  },
  methods: {
    getList() {
      this.goodsLoading = true
      getGoodsList({}).then(res => {
        this.goodsList = res.rows
        this.goodsLoading = false
      })
    },
    goRouter(item) {
      if (!sessionStorage.getItem('userToken')) {
        this.$alert('请登录', '系统提示', {
          confirmButtonText: '确定',
          callback: action => {
            this.$router.push({ path: '/dianShangLogin' }).catch(() => { });
          }
        });
      } else {
        this.$store.dispatch('loadGoodsDetail', item).then(() => {
          this.$router.push({
            path: '/goodsDeatil'
          })
        }).catch(e => {

        })
      }
    }
  },
  destroyed() {
    EventBus.$off('share')
  }
}
</script>

<style lang="scss" scoped>
  .seckill {
    margin: 15px auto;
    background-color: #fff;
  }
  .seckill-head {
    width: 100%;
    height: 50px;
    background-color: #e01222;
  }
  .seckill-icon {
    width: 68px;
    height: 100%;
    float: left;
  }
  .seckill-icon img {
    width: 35px;
    height: 35px;
    margin-top: 6px;
    margin-left: 15px;
    animation-name: shake-clock;
    animation-duration: 0.3s;
    animation-iteration-count: infinite; /*设置无线循环*/
  }
  /*定义闹钟震动动画关键帧*/
  @keyframes shake-clock {
    0% {
      transform: rotate(-8deg);
    }
    50% {
      transform: rotate(8deg);
    }
    100% {
      transform: rotate(-8deg);
    }
  }
  .seckill-text {
    width: 300px;
    height: 100%;
    float: left;
  }
  .seckill-text .seckill-title {
    font-size: 22px;
    line-height: 50px;
    color: #fff;
  }
  .seckill-text .seckill-remarks {
    margin-left: 5px;
    font-size: 10px;
    color: #fff;
  }
  /*倒计时*/
  .count-down {
    height: 100%;
    margin-right: 30px;
    line-height: 50px;
    float: right;
  }
  .count-down-text {
    color: #fff;
  }
  .count-down-num {
    padding: 3px;
    border-radius: 5px;
    background-color: #440106;
    font-size: 26px;
    font-weight: bold;
    color: #f90013;
  }
  .count-down-point {
    font-size: 26px;
    font-weight: bold;
    color: #440106;
  }

  .seckill-content {
    width: 100%;
  }
  .seckill-item {
    width: 183px;
    height: 250px;
    margin-top: 15px;
    margin-left: 18px;
    box-shadow: 0px 0px 8px #ccc;
    cursor: pointer;
    float: left;
  }
  .seckill-item-img {
    width: 160px;
    height: 160px;
    margin: 0px auto;
    overflow: hidden;
    border-bottom: 1px solid #ccc;
    background-color: #fff;
  }
  .seckill-item-img img {
    width: 130px;
    height: 130px;
    // margin-left: 15px;
    margin-top: 15px;
    transition: margin-top 0.3s;
  }
  .seckill-item-img:hover img {
    margin-top: 6px;
    transition: margin-top 0.3s;
  }
  .seckill-item-info {
    padding: 5px;
    padding-left: 15px;
    padding-right: 15px;
    font-size: 12px;
    color: #009688;
    .item-title {
      // （用来限制在一个块元素显示的文本的行数，2 表示最多显示 2 行。为了实现该效果，它需要组合其他的 WebKit 属性）
      -webkit-line-clamp: 2;
      // （和 1 结合使用，将对象作为弹性伸缩盒子模型显示 ）
      display: -webkit-box;
      // （和 1 结合使用 ，设置或检索伸缩盒对象的子元素的排列方式 ）
      -webkit-box-orient: vertical;
      // （文本溢出限定的宽度就隐藏内容）
      overflow: hidden;
      // （多行文本的情况下，用省略号 “…” 隐藏溢出范围的文本)
      text-overflow: ellipsis;
    }
  }
  .seckill-item-info i:first-child {
    font-size: 14px;
  }
  .seckill-price {
    margin-right: 5px;
    font-size: 25px;
    font-weight: bold;
  }
  .seckill-old-price {
    text-decoration: line-through;
  }
</style>